﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Net.Mail;
using System.Data;

namespace WebSite
{
    public class LogFile
    {
        readonly static log4net.ILog loggerGenerate = log4net.LogManager.GetLogger("RollingFileAppender");
        readonly static log4net.ILog loggerEmail = log4net.LogManager.GetLogger("SmtpAppender");

        public static void Write(ELogType logType, string sMessage)
        {
            if (logType == ELogType.Debug)
            {
                loggerGenerate.Debug(sMessage);
            }
            else if (logType == ELogType.Error)
            {
                loggerGenerate.Error(sMessage);
            }
            else if (logType == ELogType.Fatal)
            {
                loggerGenerate.Fatal(sMessage);
            }
            else if (logType == ELogType.Info)
            {
                loggerGenerate.Info(sMessage);
            }
            else if (logType == ELogType.Warn)
            {
                loggerGenerate.Warn(sMessage);
            }
        }

        //public static void SendEmail(ELogType logType, string sMessage)
        //{
        //    if (logType == ELogType.Debug)
        //    {
        //        loggerEmail.Debug(sMessage);
        //    }
        //    else if (logType == ELogType.Error)
        //    {
        //        loggerEmail.Error(sMessage);
        //    }
        //    else if (logType == ELogType.Fatal)
        //    {
        //        loggerEmail.Fatal(sMessage);
        //    }
        //    else if (logType == ELogType.Info)
        //    {
        //        loggerEmail.Info(sMessage);
        //    }
        //    else if (logType == ELogType.Warn)
        //    {
        //        loggerEmail.Warn(sMessage);
        //    }
        //}


        // Methods
        public static void SendEmail(string sMesasge)
        {
            string sShopEmail = info.info1("", "shopemail").ToString();
            string[] strArray = sShopEmail.Split(new char[] { '@' });
            //strArray[0] = "alvin@haolicard.com";
            //strArray[1] = "xinnetvip.com";

          
            SmtpClient client = new SmtpClient();

            client.Host = "smtp." + strArray[1]; //.xinnetvip.com

            client.Credentials = new System.Net.NetworkCredential(strArray[0], info.info1("", "shopwebmsg").ToString());
            MailMessage message = new MailMessage(sShopEmail, "zyh_100@126.com", "阳澄湖网站错误", sMesasge);


            try
            {

                client.Send(message);
                //SQLAccess.DoSql("update  tbMember set videcode='" + videcode + "' where memberid=" + table.Rows[0]["memberid"].ToString() + "");

            }
            catch (Exception ex)
            {
            }
        }


    }

    public enum ELogType
    {
        Debug = 0,
        Error,
        Fatal,
        Warn,
        Info
    }
}